<?php 
namespace app\index\model;

use think\Model;
use think\Db;

/**
* 后台用户控制器
*/
class Systemmessage extends Model
{
	protected $table = 'systemmessage';//表名
	
	// 添加消息
	public function insertMessage($userId,$content,$title='系统消息')
	{
		$array = [
			'touser' => $userId,
			'messageContent' => $content,
			'messageTime' => time(),
            'messageTitle'=>$title
		];
		return Db::table($this->table)->insert($array);
	}

	// 查看未读消息列表
	public function listMessage($userId)
	{
		return Db::table($this->table)->where('touser',$userId)->where('status',0)->select();
	}
	// 查看已读消息
	public function listReadMessage($userId)
	{
		return Db::table($this->table)->where('touser',$userId)->where('status',1)->select();
	}

	// 修改状态
	public function updateStatus($messageId)
	{
		return Db::table($this->table)->update(['status'=>1,'messageId'=>$messageId]);
	}
	// 查看未读的详情信息
	public function seeDetails($messageId)
	{
		return Db::table($this->table)->where('messageId',$messageId)->find();
	}
	// 删除消息记录
	public function deleteMessage($messageId)
	{
		return Db::table($this->table)->where('messageId',$messageId)->delete();
	}
}